package cc.iotkit.data.service;

import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.mapper.IJPACommData;
import cc.iotkit.data.manager.IProtocolComponentData;
import cc.iotkit.data.model.TbProtocolComponent;
import cc.iotkit.model.protocol.ProtocolComponent;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Primary
@Service
public class ProtocolComponentDataImpl implements IProtocolComponentData, IJPACommData<ProtocolComponent, String, TbProtocolComponent> {

    @Resource
    private ProtocolComponentService protocolComponentService;

    @Override
    public ProtocolComponentService getBaseRepository() {
        return protocolComponentService;
    }

    @Override
    public Class getJpaRepositoryClass() {
        return TbProtocolComponent.class;
    }

    @Override
    public Class getTClass() {
        return ProtocolComponent.class;
    }

    @Override
    public List<ProtocolComponent> findByState(String state) {
        return protocolComponentService.findByState(state);
    }

    @Override
    public List<ProtocolComponent> findByStateAndType(String state, String type) {
        return protocolComponentService.findByStateAndType(state, type);
    }

    @Override
    public List<ProtocolComponent> findByUid(String uid) {
        return protocolComponentService.findByUid(uid);
    }

    @Override
    public Paging<ProtocolComponent> findByUid(String uid, int page, int size) {
        return protocolComponentService.findByUid(uid, page, size);
    }

    @Override
    public long countByUid(String uid) {
        return protocolComponentService.countByUid(uid);
    }


    @Override
    public Paging<ProtocolComponent> findAll(PageRequest<ProtocolComponent> pageRequest) {

        Page<TbProtocolComponent> all = protocolComponentService.findAll(pageRequest.getPageNum(), pageRequest.getPageSize());
        return new Paging<>(all.getTotal(),
                MapstructUtils.convert(all.getRecords(), ProtocolComponent.class));
    }


}
